<!DOCTYPE>  
<html lang="zh-CN">  
      
    <head>  
        <meta charset="utf-8">  
        <title>  
            上传图片  
        </title>  
  
        <script src="/jsfiles/jQuery.js">  
        </script>  
        <script src="http://malsup.github.com/jquery.form.js">  
        </script>  
  
        <script type="text/javascript">  
            (function() {  
  
                $('#myform').ajaxForm({  
                    success: function(data) {  
                        var img = document.getElementById("preview_img");  
                        img.src = data.imgurl;     
                        img.style.display = 'block';  
                    }   
                });  
  
            })();  
        </script>  
  <script type="text/javascript">   
  var isIE = /msie/i.test(navigator.userAgent) && !window.opera;         
  function fileChange(target) {     
      
    var fileSize = 0;          
    if (isIE && !target.files) {      
      var filePath = target.value;      
      var fileSystem = new ActiveXObject("Scripting.FileSystemObject");         
      var file = fileSystem.GetFile (filePath);      
      fileSize = file.Size;     
    } else {     
     fileSize = target.files[0].size;      
     }    
     var size = fileSize / 1024;     
     if(size>1000){   
      alert("附件不能大于1M");   
     }   
}    
</script>   
        <style>  
            .Image {  
                max-width:600px;height:auto;cursor:pointer;  
                    border:1px dashed #4E6973;padding: 3px;  
                    }  
        </style>   
    </head>  
      
    <body>  
        <form id="myform" action="/photo/uploadPic.action" method="post" enctype="multipart/form-data">  
            <!-- {% csrf_token %} -->  
            <input type="file" name="uploadfile" id="image_upload"  onchange="fileChange(this);" />  
            <br>  
            <input type="submit" value="上传" />  
        </form>  
        <img id="preview_img" src="http://bcs.duapp.com/gongfumeng//upload/photo/20140814215608.jpg" width="300" height="200" class="Image" />  
    </body>  
  
</html> 